<template>
  <section class="app-container">
    <!--工具条-->
    <el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
      <el-form :inline="true" :model="filters" @submit.native.prevent>
        <el-form-item>
          <el-input v-model="filters.name" placeholder="赛事名称"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" v-on:click="getConclusion">查询</el-button>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" v-on:click="handleCon()">结题申请</el-button>
        </el-form-item>
        <el-button type="danger" @click="batchRemove" :disabled="this.sels.length===0">批量删除</el-button>
      </el-form>
    </el-col>


    <!--列表-->
    <el-table :data="conclusionData" highlight-current-row @selection-change="selsChange" style="width: 100%;">
      <el-table-column type="selection" width="55">
      </el-table-column>
      <el-table-column type="index" width="60">
      </el-table-column>
      <el-table-column prop="name" label="赛事名称" min-width="120">
      </el-table-column>
      <el-table-column prop="sum" label="总资金" min-width="100" >
      </el-table-column>
     <!-- <el-table-column prop="teacherNo" label="项目负责人" min-width="120" :formatter="formatTeacherNo">
      </el-table-column>-->
      <el-table-column prop="teamNo" label="团队编号" min-width="120">
      </el-table-column>
      <el-table-column prop="ranking" label="获奖名次" min-width="120" :formatter="formatRanking">
      </el-table-column>
      <el-table-column prop="level" label="获奖级别" min-width="120" :formatter="formatLevel">
      </el-table-column>
      <el-table-column prop="enrollTime" label="注册时间" min-width="120">
      </el-table-column>
      <el-table-column
        prop="status"
        label="审核状态"
        :filter-method="filterStatus"
        width="100"
        :filters="[{ text: '通过', value: '3' }, { text: '不通过', value: '2' },{text: '待审核', value : '1'},{text : '待提交', value : '0'}]"
        filter-placement="bottom-end">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.status == '0'"
            :type="scope.row.status === '3' ? 'primary' : 'success'"
            disable-transitions>待提交</el-tag>
          <el-tag v-if="scope.row.status == '1'"
            :type="scope.row.status === '3' ? 'primary' : 'success'"
            disable-transitions >待审核</el-tag>
          <el-tag v-if="scope.row.status == '3'"
            :type="scope.row.status === '3' ? 'primary' : 'success'"
            disable-transitions>已通过</el-tag>
          <el-tag v-if="scope.row.status == '2'"
            :type="scope.row.status === '3' ? 'primary' : 'success'"
            disable-transitions>不通过</el-tag>
        </template>
      </el-table-column>

      <el-table-column label="操作" width="240">
        <template slot-scope="scope">
          <el-button size="small" v-show="scope.row.status === '0'" type="primary" @click="handleCommit(scope.$index, scope.row)">提交</el-button>
          <el-button size="small" v-show="scope.row.status == '0' || scope.row.status == '2'" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
          <el-button size="small" type="success" @click="handleDetail(scope.$index, scope.row)">详情</el-button>
        </template>

      </el-table-column>
    </el-table>
    <!--分页工具-->
    <el-pagination
      background
      @size-change="handleSizeChange"
      :current-page="page"
      @current-change="handleCurrentChange"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="limit"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total">
    </el-pagination>


    <!--编辑界面-->
    <el-dialog
      title="项目结题"
      width="60%"
      height="60%"
      :visible.sync="dialogFormVisible"
      :close-on-click-modal="false">
      <el-form :model="editForm" label-width="120px" :rules="editFormRules" ref="editForm">
        <el-row>
          <el-col :span="8">
            <el-form-item label="赛事名称" prop="name">
              <el-select v-model="competitionName" :disabled="dialogStatus == 'detail'" filterable placeholder="请选择赛事名称">
                <el-option
                  v-for="item in projectList"
                  :key="item.name"
                  :label="item.name"
                  :value="item.name">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="获奖名次" prop="ranking">
              <el-select v-model="editForm.ranking" :disabled="dialogStatus == 'detail'" filterable placeholder="请选择获奖名次">
                <el-option label="特等奖" value="14">
                </el-option>
                <el-option label="一等奖" value="1">
                </el-option>
                <el-option label="二等奖" value="2">
                </el-option>
                <el-option label="三等奖" value="3">
                </el-option>
                <el-option label="优秀奖" value="5">
                </el-option>
                <el-option label="无" value="0">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="获奖级别" prop="level">
              <el-select v-model="editForm.level" :disabled="dialogStatus == 'detail'" filterable placeholder="请选择获奖名次">
                <el-option label="国家级" value="14">
                </el-option>
                <el-option label="区级" value="1">
                </el-option>
                <el-option label="校级" value="2">
                </el-option>
                <el-option label="无" value="0">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="注册费" prop="enroll">
              <el-input-number v-model="editForm.enroll" :min="0" :disabled="dialogStatus == 'detail'"></el-input-number>
            </el-form-item>
            <el-form-item label="差旅费" prop="travel">
              <el-input-number v-model="editForm.travel" :min="0" :disabled="dialogStatus == 'detail'"></el-input-number>
            </el-form-item>

          </el-col>
          <el-col :span="8">
            <el-form-item label="项目编号" prop="projectId">
              <el-select v-model="editForm.projectId" :disabled="dialogStatus == 'detail'" filterable placeholder="请选择赛事名称">
                <el-option
                  v-for="item in projectData"
                  :key="item.projectId"
                  :label="item.projectId"
                  :value="item.projectId">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="培训费" prop="train">
              <el-input-number v-model="editForm.train" :min="0" :disabled="dialogStatus == 'detail'"></el-input-number>
            </el-form-item>
            <el-form-item label="指导费" prop="guide">
              <el-input-number v-model="editForm.guide" :disabled="dialogStatus == 'detail'"></el-input-number>
            </el-form-item>
            <el-form-item label="耗材费" prop="consume">
              <el-input-number v-model="editForm.consume" :disabled="dialogStatus == 'detail'"></el-input-number>
            </el-form-item>
            <el-form-item label="奖金" prop="bonus">
              <el-input-number v-model="editForm.bonus" :disabled="dialogStatus == 'detail'" ></el-input-number>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="团队编号">
              <el-select v-model="teamName" :disabled="dialogStatus == 'detail'" filterable placeholder="请选择团队编号">
                <el-option
                  v-for="item in teamData"
                  :key="item.id"
                  :label="item.teamNo"
                  :value="item.teamNo">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="评审费" prop="review">
              <el-input-number v-model="editForm.review" :disabled="dialogStatus == 'detail'" ></el-input-number>
            </el-form-item>
            <el-form-item label="领队费" prop="lead">
              <el-input-number v-model="editForm.lead" :disabled="dialogStatus == 'detail'" ></el-input-number>
            </el-form-item>
            <el-form-item label="组织费" prop="organize">
              <el-input-number v-model="editForm.organize" :disabled="dialogStatus == 'detail'" ></el-input-number>
            </el-form-item>
            <el-form-item label="合计" >
              <el-input-number v-model="editForm.sum" disabled ></el-input-number>
            </el-form-item>
          </el-col>
          <el-table :data="memberData" highlight-current-row @selection-change="selsChange" style="width: 100%;">
            <el-table-column type="index" width="30">
            </el-table-column>
            <el-table-column prop="studentNo" label="学生学号" min-width="80">
            </el-table-column>
            <el-table-column prop="studentName" label="学生姓名" min-width="80">
            </el-table-column>
            <el-table-column prop="collegeName" label="所属学院" min-width="120">
            </el-table-column>
            <el-table-column prop="className" label="班级名称" min-width="120">
            </el-table-column>
            <el-table-column prop="grade" label="年级" min-width="100">
            </el-table-column>
            <el-table-column prop="major" label="专业" min-width="100">
            </el-table-column>
            <el-table-column prop="mail" label="邮箱" min-width="120">
            </el-table-column>
            <el-table-column prop="mobileNumber" label="手机号码" min-width="120">
            </el-table-column>

          </el-table>
        </el-row>


      </el-form>
      <el-form :model="projectForm" label-width="120px" v-show="dialogStatus == 'detail'" ref="editForm">
        <el-row>
          <input type="hidden" v-model="projectForm.id">
          <el-col :span="8">
            <el-form-item label="申请立项日期" prop="projectDate" >
              <el-date-picker v-show="dialogStatus != 'detail'"
                              v-model="projectForm.projectDate"
                              type="datetime"
                              placeholder="选择日期时间">
              </el-date-picker>
              <el-input v-show="dialogStatus == 'detail'" v-model="projectForm.projectDate" :disabled="dialogStatus == 'detail'" auto-complete="off" style="width: 220px;"></el-input>
            </el-form-item>
            <el-form-item label="项目负责人" prop="charge">
              <el-input v-model="projectForm.charge" :disabled="dialogStatus == 'detail'" auto-complete="off" style="width: 220px;"></el-input>
            </el-form-item>
            <el-form-item label="竞赛结束日期" prop="endDate">
              <el-date-picker v-show="dialogStatus != 'detail'"
                              v-model="projectForm.endDate"
                              type="datetime"
                              placeholder="选择日期时间">
              </el-date-picker>
              <el-input v-show="dialogStatus == 'detail'" v-model="projectForm.endDate" :disabled="dialogStatus == 'detail'" auto-complete="off" style="width: 220px;"></el-input>

            </el-form-item>
            <el-form-item label="竞赛起始日期" prop="startDate">
              <el-date-picker v-show="dialogStatus != 'detail'"
                              v-model="projectForm.startDate"
                              type="datetime"
                              placeholder="选择日期时间">
              </el-date-picker>
              <el-input  v-show="dialogStatus == 'detail'" v-model="projectForm.startDate" :disabled="dialogStatus == 'detail'" auto-complete="off" style="width: 220px;"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="专业" prop="major">
              <el-input v-model="projectForm.major" :disabled="dialogStatus == 'detail'" auto-complete="off" style="width: 220px;"></el-input>
            </el-form-item>
            <el-form-item label="组赛单位" prop="organization">
              <el-input v-model="projectForm.organization" :disabled="dialogStatus == 'detail'" auto-complete="off" style="width: 220px;"></el-input>
            </el-form-item>
            <el-form-item label="赛制" prop="format">
              <el-radio-group v-model="projectForm.format" >
                <el-radio :disabled="dialogStatus == 'detail'" class="radio" label="1">单人赛</el-radio>
                <el-radio :disabled="dialogStatus == 'detail'" class="radio" label="2">团体赛</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="主办单位" prop="sponsor" >
              <el-input v-model="projectForm.sponsor" :disabled="dialogStatus == 'detail'" auto-complete="off" style="width: 180px;"></el-input>
            </el-form-item>
            <el-form-item label="联系电话" prop="phone">
              <el-input v-model="projectForm.phone" :disabled="dialogStatus == 'detail'" auto-complete="off" style="width: 180px;"></el-input>
            </el-form-item>
            <el-form-item label="邮件" prop="mail">
              <el-input v-model="projectForm.mail" :disabled="dialogStatus == 'detail'" auto-complete="off" style="width: 180px;"></el-input>
            </el-form-item>
            <el-form-item label="竞赛承办单位" prop="contractor">
              <el-input v-model="projectForm.contractor" :disabled="dialogStatus == 'detail'" auto-complete="off" style="width: 180px;"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-form-item label="论证组赛的目的和意义" prop="objective">
          <el-input type="textarea" v-model="projectForm.objective" :disabled="dialogStatus == 'detail'" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="审核意见" v-show="projectForm.opinion != undefined">
          <el-input type="textarea" v-model="projectForm.opinion" disabled auto-complete="off"></el-input>
        </el-form-item>

        <!--        详情信息-->
        <el-form-item v-show="dialogStatus == 'detail'" label="竞赛邀请函或通知附件" prop="objective">
          <el-input v-show="dialogStatus == 'detail'" v-model="fileName" :disabled="dialogStatus == 'detail'" auto-complete="off"></el-input>
          <a :href="'http://47.100.49.86:8888/subject_competition/upload/'+ projectForm.invitation" target="_blank" v-show="dialogStatus != 'add' && projectForm.invitation != undefined">预览附件</a>
        </el-form-item>

        <!--        添加or修改-->
        <el-tooltip class="item" effect="dark" content="将签字盖章后的项目立项申请书扫描为 PDF 文档" placement="top">
          <div v-if="dialogStatus!='detail'" class="file"  style="margin-left: 40px;float: left;">
            <input v-if="dialogStatus!='detail'"  type="file" @change="getFileBase()">上传附件
          </div>
        </el-tooltip>

        <div style="margin-left: 50px;clear: both">
          <a :href="'http://47.100.49.86:8888/subject_competition/upload/'+ projectForm.invitation" v-show="dialogStatus != 'detail'" target="_blank">{{fileName}}</a>
        </div>

      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false" v-show="dialogStatus != 'detail'">取 消</el-button>
        <el-button @click.native="dialogFormVisible=false"  v-show="dialogStatus == 'detail'">关闭</el-button>
        <el-button v-if="dialogStatus != 'detail'" type="primary" @click="conclusionSave">确认</el-button>

      </div>
    </el-dialog>

  </section>
</template>

<script>
  import Vue from 'vue'
  import {dateFormat} from "../../utils/dateFomat";

  export default {
    data(){
      return{
        conclusionData:[],   // 项目结题信息
        teamList:[],   // 通过后台获取的团队数据
        teacherList:[],  // 全部教师信息
        memberList:[], // 添加的团队成员信息
        projectList:[],  // 审核通过的项目信息
        memberData:[],  // 团队成员信息存储
        teamData:[],    // 团队信息存储
        fileName:'',      // 上传的文件名称

        memberIndex:0,   // 当前选中团队成员的索引
        member:{        // 单个团队成员信息
          teamNo:"",
          studentNo:"",
          studentName:"",
          collegeName:"",
          className:"",
          grade:"",
          major:"",
          mail:"",
          mobileNumber:"",
        },
        total: 0,
        page: 1,  // 当前页
        limit: 10,  // 每页数量
        projectData: [],  // 项目立项数据
        sels: [], // 列表选中列
        competitionName:"", // 选择的赛事名称
        fileName:'',      // 上传的文件名称
        teamName:'', // 选中的团队编号
        filters: {
          name: ''
        },
        dialogStatus:"",
        memberStatus:"",
        dialogFormVisible: false,
        innerVisible:false,
        textMap: {
          update: '项目结题',
          detail: "项目结题详情",
        },
        // 项目信息
        projectForm:{
          id:0,
          projectId:0,
          budgetId:0,
          status:"",
          opinion:"",
          // 项目基本信息
          name:"",
          charge:"",
          major:"",
          format:"",
          projectDate:"",
          sponsor:"",
          contractor:"",
          objective:"",
          invitation:[],
          phone:"",
          mail:"",
          organization:"",
          startDate:"",
          endDate:"",
        },
        // 编辑界面数据
        editForm: {
          id:0,
          name:"",
          projectId:"",
          teamNo:"",
          enrollTime:"",


          prizeId:"",
          capitalId:"",
          status:"",

          // 获奖情况
          prizeId:0,
          ranking:"",
          level:"",


          // 实际资金使用
          capital:0,
          enroll:0,
          travel:0,
          train:0,
          guide:0,
          bonus:0,
          other:0,
          consume:0,
          review:0,
          lead:0,
          organize:0,
          sum:0,
        },
        projectFormRules:{
          name: [{ required: true, message: '请输入赛事名称', trigger: 'blur' }],
          // charge: [{ required: true, message: '请输入项目负责人', trigger: 'blur' }],
          major: [{ required: true, message: '请输入专业', trigger: 'blur' }],
          format: [{ required: true, message: '请选择赛制', trigger: 'blur' }],
          mail: [{ required: true, message: '请输入邮件', trigger: 'blur' }],
          phone: [{ required: true, message: '请输入联系电话', trigger: 'blur' }],
          projectDate: [{ required: true, message: '请输入申请立项日期', trigger: 'blur' }],
          sponsor: [{ required: true, message: '请输入主办单位', trigger: 'blur' }],
          // charge: [{ required: true, message: '请输入项目负责人', trigger: 'blur' }],
          organization: [{ required: true, message: '请输入组赛单位', trigger: 'blur' }],
          startDate: [{ required: true, message: '请输入竞赛起始日期', trigger: 'blur' }],
          endDate: [{ required: true, message: '请输入竞赛结束日期', trigger: 'blur' }],
          contractor: [{ required: true, message: '请输入竞赛承办单位', trigger: 'blur' }],
          objective: [{ required: true, message: '请输入论证组赛的目的和意义', trigger: 'blur' }],
          projectDate: [{ required: true, message: '请输入申请立项日期', trigger: 'blur' }],
          invitation: [{ required: true, message: '请上传竞赛邀请函或通知附件', trigger: 'blur' }],

        },
        // 数据校验
        editFormRules: {
          name:[{required: true, message: '请选择赛事名称', trigger: 'blur' }],
          // 获奖
          ranking:[{ required: true, message: '请选择获奖名次', trigger: 'blur' }],
          level:[{ required: true, message: '请选择获奖级别', trigger: 'blur' }],
          // 资金
          enroll: [{ required: true, message: '请输入注册费', trigger: 'blur' }],
          travel: [{ required: true, message: '请输入差旅费', trigger: 'blur' }],
          train: [{ required: true, message: '请输入培训费', trigger: 'blur' }],
          guide: [{ required: true, message: '请输入指导费', trigger: 'blur' }],
          consume: [{ required: true, message: '请输入耗材费', trigger: 'blur' }],
          bonus: [{ required: true, message: '请输入奖金', trigger: 'blur' }],
          review:[{ required: true, message: '请输入评审费', trigger: 'blur' }],
          lead:[{ required: true, message: '请输入指导费', trigger: 'blur' }],
          organize:[{ required: true, message: '请输入组织费', trigger: 'blur' }],
        },
        memberRules:{
          studentNo: [{required: true, message: '请输入学生学号', trigger: 'blur'}],
          studentName: [{required: true, message: '请输入学生姓名', trigger: 'blur'}],
          className: [{required: true, message: '请输入班级名称', trigger: 'blur'}],
          collegeName: [{required: true, message: '请输入所属学院', trigger: 'blur'}],
          grade: [{required: true, message: '请输入年级', trigger: 'blur'}],
          major: [{required: true, message: '请输入专业', trigger: 'blur'}],
          mail: [{required: true, message: '请输入邮箱', trigger: 'blur'}],
          mobileNumber: [{required: true, message: '请输入手机号码', trigger: 'blur'}],
        },
      }

    },
    mounted(){
      this.getConclusion();
      this.getTeacherList();
      this.getProject();
      this.getTeam();
    },
    watch:{
      // 监听选中的团队编号
      teamName(value){
        this.memberData = [];
        this.memberList.forEach((obj)=>{
          if (obj.teamNo == value){
            this.memberData.push(obj);
          }
        });
      },
      // 监听选中的赛事名称
      competitionName(value) {
        // this.teamName = '';
        // this.editForm.projectId = '';

        this.projectData = [];
        this.teamData = [];
        this.projectList.forEach((obj) => {
          if (obj.name == value) {
            this.projectData.push(obj);
          }
        });
        this.teamList.forEach((obj)=>{
          if (obj.name == value){
            this.teamData.push(obj);
          }
        });

      },



      enroll(value){
        console.log("enroll=======" + value);
        this.editForm.sum = this.editForm.sum + value;
      },
      train(value){
        console.log("enroll=======" + value);
        this.editForm.sum = this.editForm.sum + value;
      },
      travel(value){
        console.log("enroll=======" + value);
        this.editForm.sum = this.editForm.sum + value;
      },
      guide(value){
        console.log("enroll=======" + value);
        this.editForm.sum = this.editForm.sum + value;
      },

    },
    computed: {
      enroll(){
        this.editForm.sum = this.editForm.enroll + this.editForm.train + this.editForm.travel + this.editForm.organize + this.editForm.lead
          + this.editForm.guide + this.editForm.consume + this.editForm.bonus + this.editForm.review + this.editForm.review ;
      },
      train(){
        this.editForm.sum = this.editForm.enroll + this.editForm.train + this.editForm.travel + this.editForm.organize + this.editForm.lead
          + this.editForm.guide + this.editForm.consume + this.editForm.bonus + this.editForm.review + this.editForm.review ;
      },
      travel(){
        this.editForm.sum = this.editForm.enroll + this.editForm.train + this.editForm.travel + this.editForm.organize + this.editForm.lead
          + this.editForm.guide + this.editForm.consume + this.editForm.bonus + this.editForm.review + this.editForm.review ;
      },
      guide(){
        this.editForm.sum = this.editForm.enroll + this.editForm.train + this.editForm.travel + this.editForm.organize + this.editForm.lead
          + this.editForm.guide + this.editForm.consume + this.editForm.bonus + this.editForm.review + this.editForm.review ;
      },
      lead(){
        this.editForm.sum = this.editForm.enroll + this.editForm.train + this.editForm.travel + this.editForm.organize + this.editForm.lead
          + this.editForm.guide + this.editForm.consume + this.editForm.bonus + this.editForm.review + this.editForm.review ;
      },
      guide(){
        this.editForm.sum = this.editForm.enroll + this.editForm.train + this.editForm.travel + this.editForm.organize + this.editForm.lead
          + this.editForm.guide + this.editForm.consume + this.editForm.bonus + this.editForm.review + this.editForm.review ;
      },
      sum(){
        console.log("computed")
        this.editForm.sum = this.editForm.enroll + this.editForm.train + this.editForm.travel + this.editForm.organize + this.editForm.lead
          + this.editForm.guide + this.editForm.consume + this.editForm.bonus + this.editForm.review + this.editForm.review ;
      },

    },
    methods:{
      // 查询项目结题信息
      getConclusion(){
        let _this = this;
        $.ajax({
          url: "http://47.100.49.86:8888/subject_competition/json/Conclusion_list.action",
          // url: "http://localhost:8080/subject_competition/json/Conclusion_list.action",
          type: "post",
          dataType: "json",
          data: {
            name: this.filters.name,
            page: this.page,
            limit: this.limit,
          },
          success: function (res) {
            _this.conclusionData = res.data;
            _this.memberList = res.member;
            _this.total = res.count;
          }

        });

      },
      // 查询全部教师
      getTeacherList(){
        const _this = this;
        $.ajax({
          url: "http://47.100.49.86:8888/subject_competition/json/Teacher_findAll.action",
          // url: "http://localhost:8080/subject_competition/json/Teacher_findAll.action",
          type: "post",
          dataType: "json",
          success: function (res) {
            _this.teacherList = res.teacherList;
          }
        });

      },
      // 查询团队信息
      getTeam: function () {
        let teacher = localStorage.getItem("teacherId");
        // 判断当前用户是否是教师
        if (teacher === 'undefined' || teacher === 'null' || teacher === undefined || teacher === null){
          teacher = "";
        }
        var _this = this;
        $.ajax({
          url: "http://47.100.49.86:8888/subject_competition/json/Team_list.action",
          // url: "http://localhost:8080/subject_competition/json/Team_list.action",
          type: "post",
          dataType: "json",
          data: {
            name: this.filters.name,
            page: this.page,
            limit: this.limit,
            teacherNo: teacher,
          },
          success: function (res) {
            _this.teamList = res.team;
            _this.memberList = res.member;

          }
        });
      },
      // 查询项目信息
      getProject: function () {
        let charge = localStorage.getItem("teacherId");
        // 判断当前用户是否是教师
        if (charge === 'undefined' || charge === 'null' || charge === undefined || charge === null) {
          charge = "";
        }
        var _this = this;
        $.ajax({
          url: "http://47.100.49.86:8888/subject_competition/json/ProjectApply_list.action",
          // url: "http://localhost:8080/subject_competition/json/ProjectApply_list.action",
          type: "post",
          dataType: "json",
          // async:false,
          data: {
            status: "3",
            name: this.filters.name,
            page: this.page,
            limit: this.limit,
            charge: charge,
          },
          success: function (res) {
            _this.projectList = res.data;
          }
        });
      },
      // 保存or更新项目结题信息
      conclusionSave(){
        let flag = true;
        this.$refs.editForm.validate(valid => {
          if (valid) {
            this.$confirm('确认提交吗？', '提示', {})
              .then(() => {
                  const para = Object.assign({}, this.editForm);
                  if (this.dialogStatus == "add" || para.enrollTime != this.editForm.enrollTime) {
                    this.editForm.enrollTime = dateFormat.formatDate(this.editForm.enrollTime, "yyyy-MM-dd hh:mm:ss");
                  }
                  let _this = this;
                  $.ajax({
                    url: "http://47.100.49.86:8888/subject_competition/json/Capital_saveOrUpdate.action",
                    // url: "http://localhost:8080/subject_competition/json/Capital_saveOrUpdate.action",
                    data: {
                      capitalId: para.capitalId,
                      enroll: para.enroll,
                      travel: para.travel,
                      train: para.train,
                      guide: para.guide,
                      consume: para.consume,
                      bonus: para.bonus,
                      review:para.review,
                      lead:para.lead,
                      organize:para.organize,
                      sum: para.sum
                    },
                    dataType: "json",
                    async: false,
                    type: "post",
                    success: function (res) {
                      if (res.code === 0) {
                        para.capitalId = res.capitalId;
                      }else{
                        flag = false;
                      }
                    }
                  });
                  if(flag){
                    $.ajax({
                      url: "http://47.100.49.86:8888/subject_competition/json/Prize_saveOrUpdate.action",
                      // url: "http://localhost:8080/subject_competition/json/Prize_saveOrUpdate.action",
                      data: {
                        prizeId: para.prizeId,
                        ranking: para.ranking,
                        level: para.level,
                      },
                      dataType: "json",
                      async: false,
                      type: "post",
                      success: function (res) {
                        if (res.code === 0) {
                          para.prizeId = res.prizeId
                        }else {
                          flag = false;
                        }
                      }
                    });
                  }

                  if (flag) {
                    $.ajax({
                      url: "http://47.100.49.86:8888/subject_competition/json/Conclusion_saveOrUpdate.action",
                      // url: "http://localhost:8080/subject_competition/json/Conclusion_saveOrUpdate.action",
                      data: {
                        conclusionId:para.conclusionId,
                        prizeId:para.prizeId,
                        capitalId:para.capitalId,
                        teamNo:_this.teamName,
                        status: "0",
                      },
                      dataType: "json",
                      async: false,
                      type: "post",
                      success: function (res) {
                        if (res.code === 0) {
                          _this.dialogFormVisible = false;
                          _this.getConclusion();
                          Vue.prototype.$message({
                            message: "操作成功",
                            type: 'success'
                          });
                        } else {
                          flag = false;
                          Vue.prototype.$message({
                            message: "操作失败",
                            type: 'error'
                          });
                        }
                      }
                    })
                  } else {
                    Vue.prototype.$message({
                      message: "操作失败",
                      type: 'error'
                    });
                  }
              });
          }
        });
      },
      // 提交项目结题申请
      handleCommit(index, row){
        this.$confirm('确认结题该项目吗?', '提示', {
          type: 'warning'
        })
          .then(() => {
            if (row.status === "0") {
              let _this = this;
              $.ajax({
                url: "http://47.100.49.86:8888/subject_competition/json/Conclusion_saveOrUpdate.action",
                // url: "http://localhost:8080/subject_competition/json/Conclusion_saveOrUpdate.action",
                data: {
                  conclusionId: row.conclusionId,
                  prizeId: row.prizeId,
                  capitalId: row.capitalId,
                  teamNo:row.teamNo,
                  status: "1",
                },
                dataType: "json",
                type: "post",
                success: function (res) {
                  if (res.code === 0) {
                    _this.getConclusion();
                    Vue.prototype.$message({
                      message: "提交成功",
                      type: 'success'
                    });
                  } else {
                    Vue.prototype.$message({
                      message: "提交失败",
                      type: 'error'
                    });
                  }
                }

              });
            } else if (data.status === "1") {
              Vue.prototype.$message({
                message: "已经提交，不必重复提交",
                type: 'error'
              });
            }
          })  .catch(() => {
        })
      },
      // 添加团队成员
      addMember(){
        this.$refs.member.validate(valid => {
          if (valid) {
            this.$confirm('确认添加吗？', '提示', {})
              .then(() => {
                this.memberData.push(this.member);
                this.innerVisible = false;
              });
          }
        }).catch(() => { })
      },
      // 显示新增界面
      handleAdd: function () {
        this.dialogStatus = 'add'
        this.dialogFormVisible = true;
        // 置空
        this.memberData = [];
        this.editForm = {};
      },
      handleAddTeam(){
        this.memberStatus = "add";
        this.innerVisible = true;
        this.member = {};
      },
      // 显示编辑界面
      handleEdit(index, row) {
        this.memberData = [];
        this.dialogStatus = 'update'
        this.dialogFormVisible = true;

        this.memberList.forEach((obj)=>{
          if(row.teamNo === obj.teamNo){
            this.memberData.push(obj);
          }
        });
        this.teamName = row.teamNo;
        this.competitionName = row.name ;
        this.editForm = Object.assign({}, row)
      },
      // 显示项目结题申请界面
      handleCon(){
        this.fileName = ""; // 置空
        this.dialogFormVisible = true;
        this.dialogStatus = 'update';
        this.memberData = [];
      },
      // 显示详情框
      handleDetail(index, row){
        this.dialogStatus = 'detail';
        this.dialogFormVisible = true;
        this.memberData = [];
        this.projectList.forEach((obj)=>{
          if(row.projectId == obj.projectId){
            this.projectForm = obj;
            // 获取当前选中的附件信息
            this.fileName = obj.invitation;
          }
        });

        this.memberList.forEach((obj)=>{
          if(row.teamNo === obj.teamNo){
            this.memberData.push(obj);

          }
        });
        this.teamName = row.teamNo;
        this.competitionName = row.name ;
        this.editForm = Object.assign({}, row);
      },
      // 显示成员编辑界面
      memberEdit(index, row) {
        console.log("member编辑");
        this.memberStatus = 'update'
        this.innerVisible = true;
        this.member = row;

        this.memberIndex = index;
      },
      // 修改团队成员信息
      editMember(){
        this.memberData[this.memberIndex] = this.member;
        this.innerVisible = false;
      },
      // 全选单选多选
      selsChange(sels) {
        this.sels = sels
      },
      // 跳转到某页
      handleCurrentChange(val) {
        // 获取当前页
        this.page = val;
        // 重新获取数据
        this.getConclusion();
      },
      // 改变每页条数
      handleSizeChange(val){
        this.limit = val;
        this.getConclusion();
      },
      formatStatus: function (row) {
        if (row.status === "0") {
          return "待提交";
        } else if (row.status === "1") {
          return "待审核";
        } else if (row.status === "2") {
          return "不通过";
        } else if (row.status === "3") {
          return "已批准";
        }
      },
      formatRanking(row){
        if(row.ranking === "14"){
          return "特等奖";
        }else if (row.ranking === "1"){
          return "一等奖";
        } else if (row.ranking === "2"){
          return "二等奖";
        } else if (row.ranking === "3"){
          return "三等奖";
        }else if (row.ranking === "5"){
          return "优秀奖";
        }else if (row.ranking === "0"){
          return "无";
        }

      },
      formatLevel(row){
        if (row.level === "14"){
          return "国家级";
        }else if (row.level === "1"){
          return "区级";
        } else if (row.level === "2"){
          return "校级";
        }else if (row.level === "0"){
          return "无";
        }

      },
      formatTeacherNo:function(row){
        this.teacherList.forEach((obj)=>{
          if (obj.teacherId == row.teacherNo){
            row.teacherNo = obj.teacherName;
          }
        });

      },
      filterStatus(value, row){
        return row.status === value;
      },
      batchRemove(){
        let flag = true;
        var _this = this;
        this.$confirm('确认删除选中记录吗？', '提示', {
          type: 'warning'
        }).then(() => {
          this.sels.map(item =>{
            if(item.status === "3"){
              flag = false;
            }else if(item.status === "1"){
              flag = false;
            }
            if (item.conclusionId === 0){
              item.conclusionId = undefined;
            }
            if (item.prizeId === 0){
              item.prizeId = undefined;
            }
            if (item.capitalId === 0){
              item.capitalId = undefined;
            }
          });

          if(flag) {

            $.ajax({
              url: "http://47.100.49.86:8888/subject_competition/json/Conclusion_delete.action",
              // url: "http://localhost:8080/subject_competition/json/Conclusion_delete.action",
              type: "post",
              dataType: "json",
              async: false,
              data: {
                ids: JSON.stringify(this.sels)
              },
              success: function (res) {
                if (res.code === 0) {
                  _this.getConclusion();
                  Vue.prototype.$message({
                    message: "删除成功",
                    type: 'success'
                  });
                } else {
                  Vue.prototype.$message({
                    message: "删除失败",
                    type: 'error'
                  });
                }
              }
            });
          }else{
            Vue.prototype.$message({
              message: "删除失败,不能删除已经结题的项目以及在审核的项目",
              type: 'error'
            });
          }

        }).catch(() => {
          console.log("cancel");
        });


      },


    },
  }
</script>

<style scoped>
  a:link {color:blue;} /* 未访问的链接 */
  a:visited {color:orange;} /* 已访问的链接 */
  a:hover {color:green;} /* 鼠标划过链接 */
  a:active {color:red;} /* 已选中的链接 */

  .file {
    position: relative;
    display: inline-block;
    background: #D0EEFF;
    border: 1px solid #99D3F5;
    border-radius: 4px;
    padding: 4px 12px;
    overflow: hidden;
    color: #1E88C7;
    text-decoration: none;
    text-indent: 0;
    line-height: 20px;
  }
  .file input {
    position: absolute;
    font-size: 100px;
    right: 0;
    top: 0;
    opacity: 0;
    cursor: pointer
  }
  .file:hover {
    background: #AADFFD;
    border-color: #78C3F3;
    color: #004974;
    text-decoration: none;
  }
</style>
